package www.openteam.com.presenter.policy;

import java.util.ArrayList;
import java.util.HashMap;

import www.openteam.com.base.BasePresenter;
import www.openteam.com.bean.ApprlSuccess;
import www.openteam.com.bean.SendRcvPoductMsg;
import www.openteam.com.bean.SendRcvUserMsg;
import www.openteam.com.contract.policy.SendRcvApprlContract;
import www.openteam.com.model.policy.SendRcvApprlModel;
import www.openteam.com.mvp.IModel;
import www.openteam.com.ui.policy.SendRcvApprlFragment;

/**
 * Created by Administrator on 2019-06-21.
 */

public class SendRcvApprlPrst extends BasePresenter<SendRcvApprlFragment>
        implements SendRcvApprlContract.SendRcvApprlPresent {

    @Override
    public HashMap<String, IModel> getiModelMap() {
        return loadModelMap(new SendRcvApprlModel());
    }

    @Override
    public HashMap<String, IModel> loadModelMap(IModel... models) {
        HashMap<String, IModel> hashMap = new HashMap<>();
        hashMap.put("SendRcvApprlModel", models[0]);
        return hashMap;
    }

    @Override
    public void findUserMsg(String rdsno, String startDate, String endDate, String status) {
        ((SendRcvApprlModel) getiModelMap().get("SendRcvApprlModel")).findUserMsg(rdsno, startDate, endDate, status,
                new SendRcvApprlModel.UserMsgListener() {
                    @Override
                    public void success(SendRcvUserMsg sendRcvUserMsg) {
                        getIView().findUserMsg(sendRcvUserMsg);
                    }

                    @Override
                    public void fail(Throwable e) {
                        getIView().findPoductMsgFail(e.getMessage());
                    }
                });
    }

    @Override
    public void findPouductMsgType(ArrayList<String> ids) {
        ((SendRcvApprlModel) getiModelMap().get("SendRcvApprlModel")).findPoductMsg(ids, new SendRcvApprlModel.PoductMsgListener() {
            @Override
            public void success(SendRcvPoductMsg sendRcvPoductMsg) {
                getIView().findPuductMsgType(sendRcvPoductMsg);
            }

            @Override
            public void fail(Throwable e) {
                getIView().findPoductMsgFail(e.getMessage());
            }
        });
    }

    @Override
    public void audit(String checker, String checkDate, String id) {
        ((SendRcvApprlModel) getiModelMap().get("SendRcvApprlModel")).audit(checker, checkDate, id, new SendRcvApprlModel.ApprlListener() {
            @Override
            public void success(ApprlSuccess apprlSuccess) {
                getIView().audit(apprlSuccess);
            }

            @Override
            public void fail(Throwable e) {
                getIView().auditFail(e.getMessage());
            }
        });
    }

    @Override
    public void reverseAudit(String id) {
        ((SendRcvApprlModel) getiModelMap().get("SendRcvApprlModel")).reverseAudit(id, new SendRcvApprlModel.ApprlListener() {
            @Override
            public void success(ApprlSuccess apprlSuccess) {
                getIView().reverseAudit(apprlSuccess);
            }

            @Override
            public void fail(Throwable e) {
                getIView().reverseAuditFail(e.getMessage());
            }
        });
    }
}
